package io.bitark.seqserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.bitark.seqserver.alg.Sequence;
import io.bitark.seqserver.dto.GuidDTO;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/security")
public class SeqController {
	
	@Autowired
	private Sequence sequence;
	
	@GetMapping("/nextId")
	public GuidDTO nextId() {
		GuidDTO guidDTO=new GuidDTO();		
		guidDTO.setCode(1L);
		guidDTO.setMsg(String.valueOf(sequence.nextId()));
		return guidDTO;
	}

	@GetMapping("/batchIds/{size}")
	public GuidDTO batchIds(@PathVariable Integer size) {
		GuidDTO guidDTO=new GuidDTO();
		guidDTO.setCode(1L);
		List<String> ids=new ArrayList<>();
		for(int i=0;i<size;i++){
			ids.add(String.valueOf(sequence.nextId()));
		}
		guidDTO.setIds(ids);
		return guidDTO;
	}
	
}
